package com.example.easynote;

import java.util.ArrayList;

import photos.core.commons.Contants;


import com.example.easynote.R;

import DTO.AlbumModel;
import Help.Manager.Album.App;
import Help.Manager.Album.FullScreenImageAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;

/*
 * Activity xem danh sách các hình ảnh.
 */
public class FullScreenImageActivity extends Activity{

	private FullScreenImageAdapter adapter;
	private ViewPager viewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fullscreen_view);

		viewPager = (ViewPager) findViewById(R.id.pager);

		Intent i = getIntent();
		int position = i.getIntExtra(Contants.Position, 0);
		
		ArrayList<String> imagesPath = getImagesPath(i);
		if(imagesPath == null)
			return;
		
		adapter = new FullScreenImageAdapter(this,
				imagesPath);

		viewPager.setAdapter(adapter);
		viewPager.setCurrentItem(position);
	}
	
	/*
	 * Lấy danh sách Image Path từ Intent.
	 */
	private static ArrayList<String> getImagesPath(Intent i) {
		String albumPath = i.getStringExtra(Contants.AlbumPath);
		
		ArrayList<String> imagesPath = null;
		if(albumPath == null)
		{
			// Nếu Intent không chứa Album Path
			// lấy danh sách tất cả Image.
			imagesPath = App.getPhotosData().getImagesPath();
		}
		else
		{
			// Nếu Intent có chứa AlbumPath
			// lấy danh sách Image Path từ album.
			AlbumModel album = App.getAlbumsController().getAlbum(albumPath);
			if(album == null)
				return null;
			imagesPath = album.getImagesPath();
		}
		
		return imagesPath;
	}
}
